package com.example.menu;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.Toast;

import com.example.gamemenu.R;

public class IntroActivity extends Activity implements Runnable{
	
	private static final String TAG = "_MenuActivity";
	
	private ImageView imgLoading;
	private Button btnPlay, btnSetting, btnRecord;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_intro);

		initialize();
		
		Thread loadingThread = new Thread(this);
		loadingThread.start();
	}
	
	private void initialize(){
		imgLoading = (ImageView)findViewById(R.id.img_loading);
		
		btnPlay = (Button)findViewById(R.id.btn_play);
		btnSetting = (Button)findViewById(R.id.btn_setting);
		btnRecord = (Button)findViewById(R.id.btn_record);
		
	}
	
	public void onClick(View v){
		Intent intent = new Intent(getApplicationContext(), MenuActivity.class);
		
		switch(v.getId()){
		case R.id.btn_play:
			intent.putExtra(MenuActivity.MENU_TYPE, MenuActivity.MENU_PLAY);
			break;
		case R.id.btn_setting:
			intent.putExtra(MenuActivity.MENU_TYPE, MenuActivity.MENU_SETTING);
			break;
		case R.id.btn_record:
			intent.putExtra(MenuActivity.MENU_TYPE, MenuActivity.MENU_RECORD);
			break;
		}
		startActivity(intent);
	}
	
	
	@Override
	public void run() {

//		for(int i=0; i<5; i++){
		for(int i=0; i<1; i++){
			try {
				Thread.sleep(1000);
			} catch (InterruptedException e) {
				e.printStackTrace();
			}
			
			if(imgLoading.getVisibility() == View.VISIBLE){
				imgLoading.post(new Runnable() {
					
					@Override
					public void run() {
						imgLoading.setVisibility(View.INVISIBLE);
					}
				});
			} else if(imgLoading.getVisibility() == View.INVISIBLE){
				imgLoading.post(new Runnable() {
					
					@Override
					public void run() {
						imgLoading.setVisibility(View.VISIBLE);
					}
				});
			}
		}
		
		btnPlay.post(new Runnable() {
			
			@Override
			public void run() {
				btnPlay.setVisibility(View.VISIBLE);;
				btnPlay.setEnabled(true);
			}
		});
		btnSetting.post(new Runnable() {
			
			@Override
			public void run() {
				btnSetting.setVisibility(View.VISIBLE);;
				btnSetting.setEnabled(true);
			}
		});
		btnRecord.post(new Runnable() {
			
			@Override
			public void run() {
				btnRecord.setVisibility(View.VISIBLE);;
				btnRecord.setEnabled(true);
			}
		});
		
	}
	
}
